1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module pango.PgAttributeList; 26 27 private import glib.ConstructionException; 28 private import glib.ListSG; 29 private import glib.Str; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import linker.Loader; 33 private import pango.PgAttribute; 34 private import pango.PgAttributeIterator; 35 private import pango.c.functions; 36 public import pango.c.types; 37 38 39 /** 40 * A `PangoAttrList` represents a list of attributes that apply to a section 41 * of text. 42 * 43 * The attributes in a `PangoAttrList` are, in general, allowed to overlap in 44 * an arbitrary fashion. However, if the attributes are manipulated only through 45 * [method@Pango.AttrList.change], the overlap between properties will meet 46 * stricter criteria. 47 * 48 * Since the `PangoAttrList` structure is stored as a linear list, it is not 49 * suitable for storing attributes for large amounts of text. In general, you 50 * should not use a single `PangoAttrList` for more than one paragraph of text. 51 */ 52 public class PgAttributeList 53 { 54 /** the main Gtk struct */ 55 protected PangoAttrList* pangoAttrList; 56 protected bool ownedRef; 57 58 /** Get the main Gtk struct */ 59 public PangoAttrList* getPgAttributeListStruct(bool transferOwnership = false) 60 { 61 if (transferOwnership) 62 ownedRef = false; 63 return pangoAttrList; 64 } 65 66 /** the main Gtk struct as a void* */ 67 protected void* getStruct() 68 { 69 return cast(void*)pangoAttrList; 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (PangoAttrList* pangoAttrList, bool ownedRef = false) 76 { 77 this.pangoAttrList = pangoAttrList; 78 this.ownedRef = ownedRef; 79 } 80 81 ~this () 82 { 83 if ( Linker.isLoaded(LIBRARY_PANGO[0]) && ownedRef ) 84 pango_attr_list_unref(pangoAttrList); 85 } 86 87 88 /** */ 89 public static GType getType() 90 { 91 return pango_attr_list_get_type(); 92 } 93 94 /** 95 * Create a new empty attribute list with a reference 96 * count of one. 97 * 98 * Returns: the newly allocated 99 * `PangoAttrList`, which should be freed with 100 * [method@Pango.AttrList.unref] 101 * 102 * Throws: ConstructionException GTK+ fails to create the object. 103 */ 104 public this() 105 { 106 auto __p = pango_attr_list_new(); 107 108 if(__p is null) 109 { 110 throw new ConstructionException("null returned by new"); 111 } 112 113 this(cast(PangoAttrList*) __p); 114 } 115 116 /** 117 * Insert the given attribute into the `PangoAttrList`. 118 * 119 * It will replace any attributes of the same type 120 * on that segment and be merged with any adjoining 121 * attributes that are identical. 122 * 123 * This function is slower than [method@Pango.AttrList.insert] 124 * for creating an attribute list in order (potentially 125 * much slower for large lists). However, 126 * [method@Pango.AttrList.insert] is not suitable for 127 * continually changing a set of attributes since it 128 * never removes or combines existing attributes. 129 * 130 * Params: 131 * attr = the attribute to insert 132 */ 133 public void change(PgAttribute attr) 134 { 135 pango_attr_list_change(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct()); 136 } 137 138 /** 139 * Copy @list and return an identical new list. 140 * 141 * Returns: the newly allocated 142 * `PangoAttrList`, with a reference count of one, 143 * which should be freed with [method@Pango.AttrList.unref]. 144 * Returns %NULL if @list was %NULL. 145 */ 146 public PgAttributeList copy() 147 { 148 auto __p = pango_attr_list_copy(pangoAttrList); 149 150 if(__p is null) 151 { 152 return null; 153 } 154 155 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true); 156 } 157 158 /** 159 * Checks whether @list and @other_list contain the same 160 * attributes and whether those attributes apply to the 161 * same ranges. 162 * 163 * Beware that this will return wrong values if any list 164 * contains duplicates. 165 * 166 * Params: 167 * otherList = the other `PangoAttrList` 168 * 169 * Returns: %TRUE if the lists are equal, %FALSE if 170 * they aren't 171 * 172 * Since: 1.46 173 */ 174 public bool equal(PgAttributeList otherList) 175 { 176 return pango_attr_list_equal(pangoAttrList, (otherList is null) ? null : otherList.getPgAttributeListStruct()) != 0; 177 } 178 179 /** 180 * Given a `PangoAttrList` and callback function, removes 181 * any elements of @list for which @func returns %TRUE and 182 * inserts them into a new list. 183 * 184 * Params: 185 * func = callback function; 186 * returns %TRUE if an attribute should be filtered out 187 * data = Data to be passed to @func 188 * 189 * Returns: the new 190 * `PangoAttrList` or %NULL if no attributes of the 191 * given types were found 192 * 193 * Since: 1.2 194 */ 195 public PgAttributeList filter(PangoAttrFilterFunc func, void* data) 196 { 197 auto __p = pango_attr_list_filter(pangoAttrList, func, data); 198 199 if(__p is null) 200 { 201 return null; 202 } 203 204 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true); 205 } 206 207 /** 208 * Gets a list of all attributes in @list. 209 * 210 * Returns: a list of all attributes in @list. To free this value, 211 * call [method@Pango.Attribute.destroy] on each value and 212 * g_slist_free() on the list. 213 * 214 * Since: 1.44 215 */ 216 public ListSG getAttributes() 217 { 218 auto __p = pango_attr_list_get_attributes(pangoAttrList); 219 220 if(__p is null) 221 { 222 return null; 223 } 224 225 return new ListSG(cast(GSList*) __p, true); 226 } 227 228 /** 229 * Create a iterator initialized to the beginning of the list. 230 * 231 * @list must not be modified until this iterator is freed. 232 * 233 * Returns: the newly allocated 234 * `PangoAttrIterator`, which should be freed with 235 * [method@Pango.AttrIterator.destroy] 236 */ 237 public PgAttributeIterator getIterator() 238 { 239 auto __p = pango_attr_list_get_iterator(pangoAttrList); 240 241 if(__p is null) 242 { 243 return null; 244 } 245 246 return ObjectG.getDObject!(PgAttributeIterator)(cast(PangoAttrIterator*) __p, true); 247 } 248 249 /** 250 * Insert the given attribute into the `PangoAttrList`. 251 * 252 * It will be inserted after all other attributes with a 253 * matching @start_index. 254 * 255 * Params: 256 * attr = the attribute to insert 257 */ 258 public void insert(PgAttribute attr) 259 { 260 pango_attr_list_insert(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct()); 261 } 262 263 /** 264 * Insert the given attribute into the `PangoAttrList`. 265 * 266 * It will be inserted before all other attributes with a 267 * matching @start_index. 268 * 269 * Params: 270 * attr = the attribute to insert 271 */ 272 public void insertBefore(PgAttribute attr) 273 { 274 pango_attr_list_insert_before(pangoAttrList, (attr is null) ? null : attr.getPgAttributeStruct()); 275 } 276 277 alias doref = ref_; 278 /** 279 * Increase the reference count of the given attribute 280 * list by one. 281 * 282 * Returns: The attribute list passed in 283 * 284 * Since: 1.10 285 */ 286 public PgAttributeList ref_() 287 { 288 auto __p = pango_attr_list_ref(pangoAttrList); 289 290 if(__p is null) 291 { 292 return null; 293 } 294 295 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true); 296 } 297 298 /** 299 * This function opens up a hole in @list, fills it 300 * in with attributes from the left, and then merges 301 * @other on top of the hole. 302 * 303 * This operation is equivalent to stretching every attribute 304 * that applies at position @pos in @list by an amount @len, 305 * and then calling [method@Pango.AttrList.change] with a copy 306 * of each attribute in @other in sequence (offset in position 307 * by @pos, and limited in length to @len). 308 * 309 * This operation proves useful for, for instance, inserting 310 * a pre-edit string in the middle of an edit buffer. 311 * 312 * For backwards compatibility, the function behaves differently 313 * when @len is 0. In this case, the attributes from @other are 314 * not imited to @len, and are just overlayed on top of @list. 315 * 316 * This mode is useful for merging two lists of attributes together. 317 * 318 * Params: 319 * other = another `PangoAttrList` 320 * pos = the position in @list at which to insert @other 321 * len = the length of the spliced segment. (Note that this 322 * must be specified since the attributes in @other may only 323 * be present at some subsection of this range) 324 */ 325 public void splice(PgAttributeList other, int pos, int len) 326 { 327 pango_attr_list_splice(pangoAttrList, (other is null) ? null : other.getPgAttributeListStruct(), pos, len); 328 } 329 330 /** 331 * Serializes a `PangoAttrList` to a string. 332 * 333 * No guarantees are made about the format of the string, 334 * it may change between Pango versions. 335 * 336 * The intended use of this function is testing and 337 * debugging. The format is not meant as a permanent 338 * storage format. 339 * 340 * Returns: a newly allocated string 341 * 342 * Since: 1.50 343 */ 344 public override string toString() 345 { 346 auto retStr = pango_attr_list_to_string(pangoAttrList); 347 348 scope(exit) Str.freeString(retStr); 349 return Str.toString(retStr); 350 } 351 352 /** 353 * Decrease the reference count of the given attribute 354 * list by one. 355 * 356 * If the result is zero, free the attribute list 357 * and the attributes it contains. 358 */ 359 public void unref() 360 { 361 pango_attr_list_unref(pangoAttrList); 362 } 363 364 /** 365 * Update indices of attributes in @list for a change in the 366 * text they refer to. 367 * 368 * The change that this function applies is removing @remove 369 * bytes at position @pos and inserting @add bytes instead. 370 * 371 * Attributes that fall entirely in the (@pos, @pos + @remove) 372 * range are removed. 373 * 374 * Attributes that start or end inside the (@pos, @pos + @remove) 375 * range are shortened to reflect the removal. 376 * 377 * Attributes start and end positions are updated if they are 378 * behind @pos + @remove. 379 * 380 * Params: 381 * pos = the position of the change 382 * remove = the number of removed bytes 383 * add = the number of added bytes 384 * 385 * Since: 1.44 386 */ 387 public void update(int pos, int remove, int add) 388 { 389 pango_attr_list_update(pangoAttrList, pos, remove, add); 390 } 391 392 /** 393 * Deserializes a `PangoAttrList` from a string. 394 * 395 * This is the counterpart to [method@Pango.AttrList.to_string]. 396 * See that functions for details about the format. 397 * 398 * Params: 399 * text = a string 400 * 401 * Returns: a new `PangoAttrList` 402 * 403 * Since: 1.50 404 */ 405 public static PgAttributeList fromString(string text) 406 { 407 auto __p = pango_attr_list_from_string(Str.toStringz(text)); 408 409 if(__p is null) 410 { 411 return null; 412 } 413 414 return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true); 415 } 416 }